package com.erp.controller;

import com.erp.mapper.DepotMapper;
import com.erp.mapper.vo.DepotAndAddress;
import com.erp.mapper.vo.DepotAndGoods;
import com.erp.tool.PgTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class DepotController {

    @Autowired
    private DepotMapper mapper;

    //查询库区库房
    @RequestMapping("/allDepotAndAddess")
    public List findAllDepots(){
        return mapper.findDepotAndAddress();
    }

    //分页查询库区
    @RequestMapping("/limitDepotAndAddess")
    public List limitDepots(int num){
        List<Object>allList = new ArrayList<Object>();
        int row =3;
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("end",row);
        map.put("start", PgTool.getStart(num,row).get("start"));
        allList.add(PgTool.getPage(row, mapper.countDepotAndAddress()));
        allList.add(mapper.limitDepotAndAddress(map));
        return allList;
    }

    //条件查
    @RequestMapping("/conditionDepotAndAddress")
    public DepotAndAddress conditionDepotAndAddress(String name){
        return mapper.conditionDepotAndAddress(name);
    }

    //查询库房商品数量
    @RequestMapping("/findDepotAndGoods")
    public List findDepotAndGoods(){
        Map<String, Object>map=new HashMap<>();
        List<DepotAndGoods> allDepotAndGoods = mapper.findAllDepotAndGoods();
        return  allDepotAndGoods;
    }

    //分页查
    //@LoginRequired
    @RequestMapping("/limitDepot")
    public List limitUsers(String name,int num){
        List<Object>allList = new ArrayList<Object>();
        int row=4;
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("name",name);
        map.put("end",row);
        map.put("start", PgTool.getStart(num,row).get("start"));
        //查询需多少页
        allList.add(PgTool.getPage(row, mapper.countDepots(map)));
        //得到分页数据
        allList.add(mapper.findAllDepots(map));
        return allList;
    }
}
